<template>
  <div>
    <el-dialog
      v-dialogDrag
      class="dialogClass"
      :title="$t('menu.materielList')"
      model
      :visible.sync="openDialog"
      :close-on-click-modal="false"
      width="60%"
      destroy-on-close
    >
      <jc-table
        serial
        :table-data="reverseBomData"
        table-height="62.8vh"
        :table-header="reverseBomHeader"
        @clickRow="openTag"
      />
      <jc-pagination
        v-show="reversePage.total > 0"
        :total="reversePage.total"
        :page.sync="reversePage.pageNum"
        :limit.sync="reversePage.size"
        @pagination="getBomFatherList"
      />
    </el-dialog>
  </div>
</template>

<script>
import { queryBomFatherList } from '@/api/engineering/deitalBom'

export default {
  name: 'Index',
  props: {
    matId: {
      type: [Number, String],
      required: true,
      default: 0
    }
  },
  data() {
    return {
      fbillNo: 'fnumber',
      openDialog: false, // 默认关闭弹窗
      reverseBomData: [], // 反查bom数据
      reverseBomHeader: [
        { label: this.$t('market.fmaterial'), prop: 'FNUMBER' },
        { label: this.$t('shop.fname2'), prop: 'FNAME' },
        { label: this.$t('market.fdescripTion'), prop: 'FDESCRIPTION' }
      ],
      reversePage: {
        total: 0, // 总条目
        pageNum: 1, // 当前页
        pageSize: 50 // 每页显示多少条数据
      }
    }
  },
  methods: {
    // 获取数据物料
    async getBomFatherList() {
      this.openDialog = true
      const { pageNum, pageSize } = this.reversePage
      const { data: res, code, message } = await queryBomFatherList({
        matId: this.matId,
        pageNum,
        pageSize,
        ...this.selectData
      })
      const { total, list } = res
      if (list.length === 0) {
        this.$message.warning('该物料没有数据')
      } else if (code !== 0) {
        this.$confirm(message, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'error'
        })
        return
      }
      this.reverseBomData = list
      this.reversePage.total = total
    },
    openTag(item) {
      const { FNUMBER } = item
      this.$router.push({ path: `/treeBom/${FNUMBER}` })
      this.openDialog = false
    }
  }
}
</script>

<style scoped lang="scss"></style>
